#include "ParticleCollection.h"

ParticleIter::ParticleIter() 
	:
collection(NULL) {}

ParticleIter::ParticleIter(ParticleCollection * inCol)
	:
collection(inCol) {}

glm::vec3 & ParticleIter::prevAccel() {
	return collection->mPrevAccel[ndx];
}

const glm::vec3 & ParticleIter::cPos() const {
	return collection->mPos[ndx];
}

glm::vec3 & ParticleIter::pos() {
	return collection->mPos[ndx];
}

float &  ParticleIter::mass() {
	return collection->mMass[ndx];
}

const float &  ParticleIter::cMass() const {
	return collection->mMass[ndx];
}

glm::vec3 & ParticleIter::vel() {
	return collection->mVel[ndx];
}

const glm::vec3 & ParticleIter::cVel() const {
	return collection->mVel[ndx];
}


glm::vec3 & ParticleIter::force() {
	return collection->mF[ndx];
}

ParticleIter &  ParticleIter::operator++ () {
	ndx++;
	return *this;
}

ParticleIter &  ParticleIter::operator-- () {
	ndx--;
	return *this;
}
	
bool ParticleIter::operator!= (const ParticleIter & rhs) const {
	return (rhs.ndx != ndx);
}
///



void ParticleCollection::Insert( const ParticleDef & inPart ) {
	mPos.push_back(inPart.pos);
	mMass.push_back(inPart.mass);
	mF.push_back(glm::vec3(0,0,0));
	mVel.push_back(inPart.vel);
	mPrevAccel.push_back(glm::vec3(0,0,0));
}

void ParticleCollection::Remove( unsigned int partNum ){
	mPos.erase(mPos.begin() + partNum);
	mMass.erase(mMass.begin() + partNum);
}

ParticleIter ParticleCollection::Begin() {
	ParticleIter it(this);
	it.ndx = 0;
	return it;
}

unsigned int ParticleCollection::Size() {
	return mPos.size();
}

ParticleIter ParticleCollection::End() {
	ParticleIter it(this); 
	it.ndx = Size();
	return it;
}

ParticleIter ParticleCollection::operator[] ( unsigned int i ) {
	ParticleIter it(this);
	it.ndx = i;
	return it;
}